Part Number Hot Search : 
4000A VB525SP SMAJ110A C9219A SI4433 15500 1N5333B SW26000E
Product Description
Full Text Search
 

To Download AN10315-15 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  an10315 led dimmer demoboard rev. 01 ? 7 january 2005 application note document information info content keywords i 2 c, led, rgb, led controller, led dimmer, led blinker, color mixing, rgb mixing, rgb led, white led, back lighting, gpio, i/o expander, keypad control, led dimmer evaluation board, i 2 c evaluation board, pca9531, pca9533, pca9555, pca9564, p89lv51rd2 abstract 8-bit tri-color led demonstration bo ard description, features and operation modes are discussed. source code in c language, containing communication routines between an 80c51-core microcontroller + pca9564 and the i 2 c slave devices is provided: keypad control, led control / color mixing.
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 2 of 45 philips semiconductors an10315 led dimmer demoboard contact information for additional information, please visit: http://www.semiconductors.philips.com for sales office addresses, please send an email to: sales.addresses@www.semiconductors.philips.com revision history rev date description 01 20050107 application note (9397 750 14062); initial version.
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 3 of 45 philips semiconductors an10315 led dimmer demoboard 1. introduction the led dimmer demobo ard demonstrates the capability of the i 2 c-bus to control a keypad and perform red/green/blue led lighting color mixing operations. the demoboard is a st and alone solution using the ph ilips p89lv51rd2 microcontroller interfacing with a philips pca9564 i 2 c-bus controller to generate the different i 2 c commands. the microcontroller comes programmed with a default firmware that is explained in this application note. if additional programming is required, the user must remove the microcontroller from its socket and use an external programmer. the demoboard is composed by 2 sub-boards that are directly connected to each other without the need for external cables:  the keypad control card contains the microcontroller, the keypad with the keypad controller and the power supply/regulator module (external 9 v power supply or 9 v battery).  the led control card cont ains all the leds and t he devices controlling them. each card can be used separately and can be connected to other companion cards. i 2 c slave devices used on the demoboard are the following:  philips pca9555pw, 16-bit gpio functi oning as a 16-key keypad controller.  philips pca9531pw and pca953 3dp/01, 8-bit and 4-bit le d dimmer for led control and color mixing (red, green and white leds, rgb leds). 2. ordering information the complete demoboard kit consists of:  the keypad control card  the led display card kit can be obtained through y our local philips semi conductors sales organization or via e-mail to i2c.support@philips.com
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 4 of 45 philips semiconductors an10315 led dimmer demoboard 3. technical information?hardware 3.1 block diagram 3.2 i 2 c-bus device addresses fig 1. block diagram p89lv51 rd2 pca 9564 pca 9555 16-key keypad pca 9533 pca 9531 pca 9531 pca 9531 pca 9531 4 white leds 8 rgb leds misc/status leds - 4 red leds - 1 green led - 1 blue led - 1 rg led /int 3.3 v regulator 9 v battery or 9 v power supply keypad control card led control card data / control reset ` scl sda /reset table 1: i 2 c-bus device addresses device type description i 2 c address (hexadecimal) p89lv51rd2/pca9564pw microcontroller / i 2 c-bus controller user definable when slave pca9531pw (red - rgb leds) 8-bit i 2 c led dimmer 0xca pca9531pw (green - rgb leds) 8-bit i 2 c led dimmer 0xcc pca9531pw (blue - rgb leds) 8-bit i 2 c led dimmer 0xce pca9531pw (misc/status leds) 8-bit i 2 c led dimmer 0xc6 pca9533dp/01 (white leds) 4-bit i 2 c led dimmer 0xc4 pca9555 16-bit i 2 c gpio 0x46
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 5 of 45 philips semiconductors an10315 led dimmer demoboard 3.3 schematic 3.3.1 keypad control card fig 2. keypad control card schematic rst 2 3 4 5 6 7 8 9 35 33 10 32 p89lv51ra2 gnd c6 22 pf c5 22 pf c4 1 f r5 1 k ? 1 2 3 4 s17 gnd q1 11.0592 mhz 1 2 21 20 xtal1 xtal2 psen\ rst ale-prog\ ea\-vpp gnd vss 22 cex4-p1.7 cex3-p1.6 cex2-p1.5 vcc 44 u$1 cex1-p1.4 cex0-p1.3 eci-p1.2 t2ex-p1.1 t2-p1.0 gnd c2 100 nf rd\-p3.7 wr\-p36 t1-p3.5 t0-p3.4 int1\-p3.3 int0\-p3.2 txd-p3.1 rxd-p3.0 19 18 17 16 ? 1 k 9 v gnd gnd2 15 14 13 11 p2.7-a15 p2.6-a14 p2.5-a13 p2.4-a12 p2.3-a11 p2.2-a10 p2.1-a9 p2.0-a8 31 30 29 28 27 26 25 24 p0.7-ad7 p0.6-ad6 p0.5-ad5 p0.4-ad4 p0.3-ad3 p0.2-ad2 p0.1-ad1 p0.0-ad0 36 37 38 39 40 41 42 43 d7 d6 d5 d4 d3 d2 d1 d0 pin8 pin7 pin6 pin5 pin4 pin3 pin2 pin1 u$2 vdd pin20 pin19 pin18 d7 d6 d5 d4 d3 d2 d1 d0 gnd c1 100 nf intpca9555 reset\ int\ wr\ rd\ a0 a1 rn1 4.7 k ? 1 23456 789 pin15 pin14 pin16 pin17 reset\ int\ wr\ rd\ a0 a1 pin12 pin11 pin13 sda scl ce\ pca9564pw pin10 vss gnd vcc3 c7 100 f r6 1.5 k ? r4 1 k ? ic1 in out adj u$4 sk14 c8 100 nf gnd r7 1 k ? ld1 g1 ab9v ? + + + ? gnd rst intpca9555 scl0 sda0 vcc3 1 2 3 4 jp4 1 2 jp1 1 2 jp6 1 2 jp2 1 2 jp7 1 2 3 4 jp3 1 2 3 4 jp5 gnd 21 2 3 a2 a1 a0 23 22 sda scl vdd gnd pca9555pw 12 int\ 1 intpca9555 sda0 scl0 24 c3 100 nf gnd r2 10 k ? r3 10 k ? r1 10 k ? u$3 io07 io06 io05 io04 io03 io02 io01 io00 io17 io16 io15 io14 io13 io12 io11 io10 11 10 9 8 7 6 5 4 20 19 18 17 16 15 14 13 gnd 1 2 3 4 s16 1 2 3 4 s15 1 2 3 4 s14 1 2 3 4 s13 1 2 3 4 s12 1 2 3 4 s11 1 2 3 4 s10 1 2 3 4 s9 1 2 3 4 s8 1 2 3 4 s7 1 2 3 4 s6 1 2 3 4 s5 1 2 3 4 s4 1 2 3 4 s3 1 2 3 4 s2 1 2 3 4 s1
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 6 of 45 philips semiconductors an10315 led dimmer demoboard 3.3.2 led control card fig 3. led control card schematic pca24s08dp 74lvc1g04gw pca9531pw pca9533dp pca9531pw pca9531pw pca9531pw ld12 ld11 ld9 ld8 ld7 ld6 ld5 ld4 ld3 ld2 ld1 120 r27 120 r28 120 r26 120 r25 pin1 pin2 pin3 pin5 led0 led1 led2 led3 gnd gnd pin4 pin8 gnd u$7 sda scl pin7 pin6 c1 100 n 150 r29 150 r30 150 r31 150 r32 150 r33 150 r34 120 r35 0 r36 v cc v dd sda scl led0 v dd led1 led2 led3 pin18 gnd u$5 c2 100 n gnd pin15 pin14 pin13 reset led4 led5 led6 led7 pin4 pin5 pin6 pin7 pin9 pin10 v ss pin11 pin12 a0 a1 a2 pin1 pin2 pin3 v cc pin8 reset gnd /int 3 2 1 4 2 1 2 1 2 1 2 1 3 2 1 4 3 2 1 4 jp4 jp1 jp7 jp5 jp3 jp2 jp6 reset u$4 24 sda0 scl0 pin8 v ss v cc u$6 sda scl pin5 pin6 gnd pin4 /prot wp pin3 pin7 pin1 pin2 pin3 a0 a1 a2 v ss sda scl reset pin15 pin14 pin13 u$3 v dd pin16 pin8 gnd v ss gnd pin8 a0 a1 a2 pin1 pin2 pin3 v dd pin16 u$2 sda scl reset pin15 pin14 pin13 v ss gnd pin8 a0 a1 a2 pin1 pin2 pin3 u$1 sda scl reset pin15 pin14 pin13 v dd pin16 c3 100 n gnd led0 led1 led2 led3 led4 led5 led6 led7 led0 led1 led2 led3 led4 led5 led6 led7 led0 led1 led2 led3 led4 led5 led6 led7 c4 100 n gnd pin4 pin5 pin6 pin7 pin9 pin10 pin11 pin12 pin4 pin5 pin6 pin7 pin9 pin10 pin11 pin12 c5 100 n gnd pin4 pin5 pin6 pin7 pin9 pin10 pin11 pin12 120 r16 120 r12 0 r17 0 r20 0 r18 0 r19 0 r22 0 r21 0 r23 0 r24 120 r15 120 r14 120 r13 120 r11 120 r10 120 r9 ld13 ld14 ld15 ld16 ld17 ld18 ld19 ld20 150 r5 150 r8 150 r7 150 r6 150 r4 150 r3 150 r1 150 r2
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 7 of 45 philips semiconductors an10315 led dimmer demoboard 3.4 demoboard (top view) fig 4. schematic keypad control card connectors for external master or slave card p89lv51rd2 reset pushbutton pca9564 connectors between the boards - power supply - i 2 c-bus - reset signal -/int signal (not used) pca9531 blue pca9531 green pca9555 pca9531 red pca9531 misc/status pca9533 8 rgb leds: ld13 to ld18 4 white leds: ld1 to ld4 misc/status leds: ld5 to ld8 misc/status leds: ld9, ld11, ld12 external 9 v battery or external 9 v power supply keypad
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 8 of 45 philips semiconductors an10315 led dimmer demoboard 3.5 rgb color mixing red, green and blue are the 3 primary colors allowing creating all the other colors by mixing them together. the desired color is created by applying the right amount of red, plus the right amount of green plus the right amount of blue light from the rgb led. a 152 hz frequency voltage is applied to the red, green and blue led drivers so that the human eye does not see the on/off cycle (typically frequencies higher than100 hz are required). varying the duty cycle controls the average current flowing through the led, thus controlling the brightness for each color. the human eye se es an average brightness value since it cannot see the on/off cycle. the sum of the 3 primary colors at various br ightness values will then define the resulting color: + + gives the desired visible color. fig 5. color mi xing theory + + = voltage on red led driver voltage on green led driver voltage on blue led driver resulting color
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 9 of 45 philips semiconductors an10315 led dimmer demoboard 4. technical information? how to use the demobord 4.1 introduction firmware in the p89lv51rd2 microcontroller emulates a cell phone application, programs fun patterns, and controls the brightness of a virtual display. a battery discharge emulation with a visual charge status can also be performed. the firmware is intended to show a specific application (i.e., cell phone), but this demoboard can be used for any application that requires a keypad control and led lighting/color mixing. most of the code, written in c language, has been re-used from the pca9564 evaluation board (drivers, main interfacing files between the p89lv51rd2 and the pca9564). only the mainloop.c , i2c_routines.c and i2cexprt.h files have been modified to implement the code specific to the demoboard. for more information about the files different from the 3 mentioned above, refer to the application notes an10149: pca9564 evaluation board , and to the pca9564 evaluation board main page at: http://www.standardprod ucts.philips.com/support/boards/pca9564/ . the default firmware in the p89lv51rd2 allows the user to:  control the 16-key keypad (numbers from 0 to 9 are displayed in binary code)  control the rgb leds and program 3 different colors / display speed  control the brightness of the white leds  emulate a ?battery discharge? application  enable an ?auto demo mode? showing so me ?fun light? application / rgb mixing the p89lv51rd2 can be programmed with any user defined firmware. since the demoboard does not have any built-in programming feature, the user must then program the microcontroller with an external programmer. default firmware (source files and ?.hex? file) can be downloaded from the following link: http://www.standardprod ucts.philips.com/support/boards/leddemo/ .
xxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x xxxxxxxxxxxxxx xxxxxxxxxx xxx xxxxxx xxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxx xxxxx xxxxxx xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxx xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx xxxxx x x 9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 10 of 45 philips semiconductors an10315 led dimmer demoboard 4.2 firmware routines fig 6. firmware routines flowchart power up or reset dialing routine key f1 pushed? key f2 pushed? key 1 pushed? ld12 blinking key 2 pushed? key 3 pushed? key 4 pushed? key end pushed? ld5 on programming fun pattern 1 routine key end pushed? ld5 off yes yes no no no no no no no yes ld6 on programming fun pattern 2 routine key end pushed? ld6 off ld7 on programming fun pattern 3 routine key end pushed? ld7 off ld8 on white led control routine key end pushed? ld8 off yes yes yes programming mode yes yes yes yes no no no no ld11 blinking yes emulation mode key 1 pushed? battery emulation routine key end pushed? yes yes no ld12 off key 4 pushed? auto demo routine yes key end pushed? no yes ld11 off no no only a reset exits the auto demo routine
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 11 of 45 philips semiconductors an10315 led dimmer demoboard 4.3 dialing routine 4.3.1 how the keypad control works keypad control is done using a pca9555 with its int signal connected to a gpio of the p89lv51rd2 microcontroller. the 16 keys of the keypad are simply connected to the 16 gpios of the pca9555 and to the ground, without any other external components since internal 100 k ? pull-ups are provided by the pca9555. each time one (or more) key is pressed, the pca9555 generates an interrupt that is detected by the p89lv51rd2. a read of the input port registers of the pca9555 is then initiated in order to determine which key(s) has (have) been pushed. two modes are possible: 1. one time only pushed detection: only one read is performed. 2. continuous push detection: the p89lv51rd2 keeps polling the input port registers as long as the register content is different from 0xff (meaning that at least one key is pushed). code is described in the function called ?gpio_interrupt_handler()? described in section 5.3 ? i2c_routines.c ? . when an interrupt is detected, the p89lv51rd2 initiates 2 input port register readings. a delay between the 2 readings allows:  potential switch bounces to be filtered.  detection of a one time or continuous push detection. the delay is long enough so that if 2 readings are identical, it assumes that a continuous push is applied to the pushbutton. if the second reading is different, it assumes that the user released the pushbutton. the delay is also short enough so that a push in another key is not masked. a variable called ?gpio_pollin g_on? enable/disables the po lling option thus making the scan suitable for a ?one shot? detection. continuous push detection is enabled when set to ?1?. 4.3.2 keypad mapping with the pca9555 i/os table 2: pca9555 input port register 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 87654321 table 3: pca9555 input port register 1 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 f2 f1 end snd # * 0 9
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 12 of 45 philips semiconductors an10315 led dimmer demoboard 4.3.3 application: cell phone type keyboard?dialing routine the firmware in the p89lv51rd2 targets a cell phone type application where the keypad is used to dial phone numbers and access to a programming mode in order to access the rgb and white leds. when dialing a phone number (keys 0 to 9 are used), the pushed key value is displayed using its binary code with ld5 (msb) to ld8 (lsb). note that a maximum of 10 keys can be pushed when dialing a phone number. if more than 10 keys are entered, ld5 to ld8 will start fl ashing at 1 hz / 50 % duty cycle to let the user know that the maximum number has been reached. after dialing the number, the user has to push the snd key to send the number or the end key to end the call. ld5 to ld8 become off when those 2 keys are pushed. when snd is pushed, all eight rgb leds will blink at 1 hz / 50 % duty cycle with either a red color (visual emulating a ?busy? line) or a green color (visual emulating a ?non busy? line). pushing end ends the call and the rgb leds (red or green) are off. remark: to dial a number, the user needs to be sure that the programming mode is not enabled (ld12 is not blinking) or the emulation mode is not enabled (ld11 is not blinking). if the demoboard is either in the programming mode or in the emulation mode, the end key must be pushed one or two times (depending which branch of the firmware is active) until ld11 and ld12 are off. a reset can also be performed to reach the dialing routine. table 4: binary code for numbers from 0 to 9 key ld5 ld6 ld7 ld8 0 1 ? 2 ? 3 ?? 4 ? 5 ?? 6 ?? 7 ??? 8 ? 9 ??
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 13 of 45 philips semiconductors an10315 led dimmer demoboard 4.4 programming mode the programming mode shows capabilitie s of the pca9533 and the pca9531 led dimmers to control leds for:  rgb (red / green / blue) color mixing  white led brightness control power supply used for both i 2 c devices and leds is equal to 3.3 v. applications requiring leds connected to 5 v or even higher power supply are also possible. power supply values higher than 5 v require the use of external fet drivers. more information can be found in the application notes an264 - i 2 c devices for led display control .  programming mode is entered by pushing key f1. ld12 (blue led) starts then blinking to indicate that the programming mode is active.  keys 1, 2 and 3 select the 3 programmable ?fun patterns?. see section 4.4.1 ? programming fun patterns routine?rgb color mixing ? for more detail.  key 4 selects the white led?s control. see section 4.4.3 ? white led control routine ? for more detail. ld5 to ld8 let the user know which programming is active.  pushing key end once leaves the current programming that was performed (fun pattern 1, 2 or 3, white led control). the corresponding led (ld5 to ld8) is then off.  pushing key end one more time leaves the programming mode. ld12 stops blinking. 4.4.1 programming fun patterns routine?rgb color mixing three ?fun patterns? can be programmed when using the default firmware. for each ?fun pattern?, the user can select:  the resulting color: selection of amount or red, green and blue.  the rotating speed: ld13 ld14 ld15 ld16 ld17 ld18 ld19 ld20 ld13 for each pattern, primary colors (red, green, blue) can be added (+) or removed (-) and the rotating speed can be increased (+) or decreased (-) by pushing the corresponding key in the keypad.  key 2: red (-)  key 3: red (+)  key 5: green (-)  key 6: green (+)  key 8: blue (-) table 5: active programming programming key to be pushed ld5 ld6 ld7 ld8 fun pattern 1 1 on off off off fun pattern 2 2 off on off off fun pattern 3 3 off off on off white led control 4 off off off on
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 14 of 45 philips semiconductors an10315 led dimmer demoboard  key 9: blue (+)  key 0: speed (-)  key #: speed (+) remark: those keys have been programmed to detect a continuous push applied to them. when pushed continuously, (+) or (-) action is performed continuously until max (0xff) or min (0x00) in the pwm registers. remark: keys in this routine have been programmed to detect a continuous push applied to them. when pushed continuously, (+) or (- ) action is performed continuously until max (0xff) or min (0x00) in the pwm registers. 4.4.2 pca953x mapping with the leds 4.4.3 white led control routine brightness control for the 4 white leds is performed with the following keys:  key 2: brightness (-)  key 3: brightness (+) remark: keys in this routine have been programmed to detect a continuous push applied to them. when pushed continuously, (+) or (-) action is performed continuously until max (0xff) or min (0x00) in the pwm registers. table 6: pca933 (white leds) - ls0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 ld4 ld3 ld2 ld1 table 7: pca931 (misc/status leds) - ls0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 ld8 ld7 ld6 ld5 table 8: pca931 (misc/status leds) - ls1 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 ld12 ld11 ld9 green ld9 red table 9: pca931 (red/green/blue leds) - ls0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 ld16 ld15 ld14 ld13 table 10: pca931 (red/green/blue leds) - ls1 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 ld20 ld19 ld18 ld17
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 15 of 45 philips semiconductors an10315 led dimmer demoboard 4.5 emulation mode: battery discharge application emulation mode can be described as a mode that would require external ?stimulus? to show an application in a real environment. the example in the firmware shows a simple application where a battery discharge (for exam ple in a cell phone application) is emulated by pushing a key. a led controlled by a pca9531 is used to provide visual status of the battery level:  emulation mode is entered by pushing key f2. ld11 starts blinking.  pushing key 1 starts battery discharge emulation. ? ld5 to ld8 are on, indicating a fully charged battery (100 %). ? ld9 blinks slowly (1 hz) and hi gh duty cycle, with a green color.  pushing continuously key 3 emulates a battery discharge (from 100 % with ld5 to ld8 on, down to 0 % with ld5 to ld8 off). the different steps are explained in ta b l e 1 1 . principle is to change the led color (green, orange, red) and the led duty cycle (shorter duty cycle) to catch the user?s attention when using their cell phone.  a reset of the emulation is performed by pushing key 6. battery is then fully charged.  pushing key end exits the battery discharge emulation mode. ld5 to ld9 are off.  pushing again key end exits the emulation mode. ld11 stops blinking. remark: keys in this routine have been programmed to detect a continuous push applied to them. when pushed continuously, (+) or (-) action is performed continuously. 4.6 auto demo routine the auto demo routine shows so me light effects real time rg b mixing without having to push any buttons.  emulation mode is entered by pushing key f2. ld11 starts blinking  pushing key 4 starts the auto demo mode remark: once the auto demo mode starts (after pushing key 4), the user must use the reset button to exit the mode. 4.7 reset the reset button located in the keypad control card allows the user to reinitialize the p89lv51rd2 and the i 2 c devices and go to a known state. it causes the firmware to start again at the beginning point and initiates the dialing routine. table 11: battery discharge steps step battery charge ld5 ld6 ld7 ld8 ld9 1 100 % on on on on green - 1 hz - 93 % duty cycle 2 75 % off on on on green - 1 hz - 93 % duty cycle 3 50 % off off on on orange - 1 hz - 50 % duty cycle 4 25 % off off off on red - 1 hz - 6 % duty cycle 5 0 % off off off off red - 1 hz - 0.4 % duty cycle
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 16 of 45 philips semiconductors an10315 led dimmer demoboard 4.8 how to code i 2 c commands using the p89lv51rd2/pca9564 i 2 c messages are described using a ?structure? type definition where the i 2 c address, the number of bytes to be sent/received and a pointer to a buffer with the data are used: typedef struct { byte address; // slave address to sent/receive message byte nrbytes; // number of bytes in message buffer byte *buf; // pointer to application message buffer } i2c_message; the user must then use a variable with an ?i2c_message? type and a variable acting as a buffer that will be filled with the message to send (write operation) or filled with the message received (read operation). example 1: program the pca9531_red with br 0 at (max frequency, 50 % duty cycle) and br1 at (max frequency, 10 % duty cycle), with ld13 to ld16 blinking at br0 and ld17 to ld20 blinking at br1. idata i2c_message message1; idata byte buffer1[16]; message1.nrbytes = 7; message1.buf = buffer1; message1.address = 0xca; // i2c address pca9531 red (rgb leds) buffer1[0] = 0x11; // auto increment + register 1 buffer1[1] = 0x00; // max frequency buffer1[2] = 0x80; // 50 % duty cycle buffer1[3] = 0x00; // max frequency buffer1[4] = 0x19; // 10 % duty cycle buffer1[5] = 0x00; // red rgb led's = off buffer1[6] = 0x00; // red rgb led's = off i2c_write(&message1); // function sending the i2c sequence example 2: read the pca9555 input port registers. to perform this operation a write to the device must been initiated first in order to provide the command code (or pointer information) to decide which register(s) needs to be read. then a read is performed. idata i2c_message message2; data i2c_message message3; idata byte buffer2[16]; idata byte buffer3[16]; message2.nrbytes = 1; // the 1st message is 1 byte long message3.nrbytes = 2 // the 2nd message is 2 bytes long; message2.buf = buffer2; message3.buf = buffer3; message2.address = 0x46; // i2c address pca9555 write message3.address = 0x47; // i2c address pca9555 read buffer2[0] = 0x00; // set the command byte / pointer 1st part of the message)
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 17 of 45 philips semiconductors an10315 led dimmer demoboard i2c_writerepread(&message2,&message3); // function sending the i2c sequence after the read is performed buffer3[0] and buffer3[1] contain the input port register values. 5. source code 5.1 i2cexpert.h //************************************************************************* // p h i l i p s p r o p r i e t a r y // // copyright (c) 2003 by philips semiconductors // -- all rights reserved -- // // file name: i2cexpert.h // created: june 2, 2003 // modified: june 4, 2003 // revision: 1.00 //************************************************************************* #include typedef unsigned char byte; typedef unsigned short word; typedef unsigned long long; typedef struct // each message is configured as follows: { byte address; // slave address to sent/receive message byte nrbytes; // number of bytes in message buffer byte *buf; // pointer to application message buffer } i2c_message; typedef struct // structure of a complete transfer { // made up of a number of messages and pointers to the messages byte nrmessages; // number of message in one transfer i2c_message **p_message; // pointer to pointer to message } i2c_transfer; /***************************************************************************/ /* e x p o r t e d d a t a d e c l a r a t i o n s */ /***************************************************************************/ #define false 0 #define true 1 #define i2c_wr 0 #define i2c_rd 1 #define increment 0 #define decrement 1 #define pca9531_wr 0xc8 // i2c address led dimmer - write operation #define pca9531_rd 0xc9 // i2c address led dimmer - read operation #define pca9555_wr 0x46 // i2c address i/o expander - write operation #define pca9555_rd 0x47 // i2c address i/o expander - read operation #define pca9531_r_wr 0xca // i2c address led dimmer red - write operation #define pca9531_r_rd 0xcb // i2c address led dimmer red - read operation #define pca9531_g_wr 0xcc // i2c address led dimmer green - write operation
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 18 of 45 philips semiconductors an10315 led dimmer demoboard #define pca9531_g_rd 0xcd // i2c address led dimmer green - read operation #define pca9531_b_wr 0xce // i2c address led dimmer blue - write operation #define pca9531_b_rd 0xcf // i2c address led dimmer blue - read operation #define pca9531_m_wr 0xc6 // i2c address led dimmer misc - write operation #define pca9531_m_rd 0xc7 // i2c address led dimmer misc - read operation #define pca9533_w_wr 0xc4 // i2c address led dimmer white - write operation #define pca9533_w_rd 0xc5 // i2c address led dimmer white - read operation #define pca24s08_wr 0xa0 #define pca24s08_rd 0xa1 /**** status errors ****/ #define i2c_ok 0 // transfer ended no errors #define i2c_busy 1 // transfer busy #define i2c_error 2 // err: general error #define i2c_no_data 3 // err: no data in block #define i2c_nack_on_data 4 // err: no ack on data #define i2c_nack_on_address 5 // err: no ack on address #define i2c_device_not_present 6 // err: device not present #define i2c_arbitration_lost 7 // err: arbitration lost #define i2c_time_out 8 // err: time out occurred #define i2c_slave_error 9 // err: slave mode error #define i2c_init_error 10 // err: initialization (not done) #define i2c_retries 11 // err: initialization (not done) /***************************************************************************/ /* i n t e r f a c e f u n c t i o n p r o t o t y p e s */ /***************************************************************************/ extern void i2c_initializemaster(byte speed); extern void i2c_initializeslave(byte slv, byte *buf, byte size, byte speed); extern void i2c_installinterrupt(byte vector); extern void i2c_interrupt(void); extern void i2c_write(i2c_message *msg); extern void i2c_writerepwrite(i2c_message *msg1, i2c_message *msg2); extern void i2c_writerepread(i2c_message *msg1, i2c_message *msg2); extern void i2c_read(i2c_message *msg); extern void i2c_readrepread(i2c_message *msg1, i2c_message *msg2); extern void i2c_readrepwrite(i2c_message *msg1, i2c_message *msg2); extern void init_white(void); extern void init_rgb(void); extern void init_misc(void); extern void init_gpio(void); extern void gpio_interrupt_handler(void); extern void insertdelay(unsigned char delaytime); extern void backlight_programming(void); extern void fun_pattern_programming(void); extern void battery_status(void); extern void dial_number(void); extern void intro_patterns(void); extern void fun_pattern_display (short int red_value, short int green_value, short int blue_value, short int speed_value); extern void auto_demo(void);
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 19 of 45 philips semiconductors an10315 led dimmer demoboard static sbit led0 = p2^2; // ld[9:12] mapped with lv51's p2[2:5] static sbit led1 = p2^3; static sbit led2 = p2^4; static sbit led3 = p2^5; static sbit pca9555_int = p3^2; // interrupt pca9555 mapped with lv51's p3[2] sbit pca9564_reset = p3^4; // reset pca9564 mapped with lv51's p3[4] 5.2 mainloop.c //************************************************************************* // p h i l i p s p r o p r i e t a r y // // copyright (c) 2003 by philips semiconductors // -- all rights reserved -- // // file name: mainloop.c // created: june 2, 2003 // modified: november 07, 2003 // revision: 1.00 //************************************************************************* #include #include "i2cexprt.h" #include "pca9564sys.h" #include "i2c_routines.h" idata byte buffer1[32]; idata byte buffer2[32]; idata byte buffer3[16]; idata byte buffer4[16]; idata i2c_message message1; idata i2c_message message2; idata i2c_message message3; idata i2c_message message4; static short int programcounter = 0; //**************************************************************************** // initialization functions at power up, reset or program change //**************************************************************************** static void init_pca9564(void) { pca9564_reset = 1; pca9564_reset = 0; insertdelay(2); // pca9564 reset time = 2 ms pca9564_reset = 1; auxr = 2; // external memory space i2c_initializemaster(0x00); // 330 khz } void init_white(void) { message1.buf = buffer1; message1.nrbytes = 6;
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 20 of 45 philips semiconductors an10315 led dimmer demoboard message1.address = pca9533_w_wr; buffer1[0] = 0x11; // autoincrement + register 1 buffer1[1] = 0x00; // default prescaler pwm0 buffer1[2] = 0x10; // default duty cycle for pwm0 buffer1[3] = 0x00; // default prescaler pwm1 buffer1[4] = 0x10; // default duty cycle for pwm1 buffer1[5] = 0xaa; // ld1-ld4 on at br0 (white leds) i2c_write(&message1); } void init_rgb(void) { message1.buf = buffer1; message1.nrbytes = 7; message1.address = pca9531_r_wr; buffer1[0] = 0x11; // autoincrement + register 1 buffer1[1] = 0x00; // default prescaler pwm0 buffer1[2] = 0x6b; // default duty cycle for pwm0 buffer1[3] = 0x00; // default prescaler pwm1 buffer1[4] = 0x6b; // default duty cycle for pwm1 buffer1[5] = 0x00; // red rgb led's = off buffer1[6] = 0x00; // red rgb led's = off i2c_write(&message1); message1.address = pca9531_g_wr; buffer1[0] = 0x11; // autoincrement + register 1 buffer1[1] = 0x00; // default prescaler pwm0 buffer1[2] = 0x00; // default duty cycle for pwm0 buffer1[3] = 0x00; // default prescaler pwm1 buffer1[4] = 0x00; // default duty cycle for pwm1 buffer1[5] = 0x00; // green rgb led's = off buffer1[6] = 0x00; // green rgb led's = off i2c_write(&message1); message1.address = pca9531_b_wr; buffer1[0] = 0x11; // autoincrement + register 1 buffer1[1] = 0x00; // default prescaler pwm0 buffer1[2] = 0x25; // default duty cycle for pwm0 buffer1[3] = 0x00; // default prescaler pwm1 buffer1[4] = 0x25; // default duty cycle for pwm1 buffer1[5] = 0x00; // blue rgb led's = off buffer1[6] = 0x00; // blue rgb led's = off i2c_write(&message1); } void init_misc(void) { message1.buf = buffer1; message1.nrbytes = 7; message1.address = pca9531_m_wr; buffer1[0] = 0x11; // autoincrement + register 1 buffer1[1] = 0x97; // default prescaler pwm0 buffer1[2] = 0x80; // default duty cycle for pwm0 buffer1[3] = 0x97; // default prescaler pwm1 = 1 hz buffer1[4] = 0x08; // default duty cycle for pwm1 = 50% buffer1[5] = 0x00; // misc led's = off buffer1[6] = 0x00; // misc led's = off i2c_write(&message1); }
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 21 of 45 philips semiconductors an10315 led dimmer demoboard void init_gpio(void) { message2.address = pca9555_wr; message2.buf = buffer2; message2.nrbytes = 1; buffer2[0] = 0; // subaddress = 0 message3.address = pca9555_rd; message3.buf = buffer3; message3.nrbytes = 2; // read 2 bytes buffer3[0] = 0xff; buffer3[1] = 0xff; } //**************************************************************************** // delay time in milliseconds // insert a wait into the program flow // use timer 1 // do not use an interrupt // oscillator running at 11.0592 mhz // 6 clock cycles per clock tick // therefore, we need 1843 cycles for 1msec //**************************************************************************** void insertdelay(unsigned char delaytime) { unsigned char i; tmod = (tmod & 0x0f) | 0x01; // 16-bit timer tr1 = 0; for (i=0;i indicate led programming mode active i2c_write(&message1); // program pca9531 (2 bytes) while (buffer3[1] != 0xdf) // loop as long as end button not pushed (programming mode active) { buffer3[1] = 0xff; // clear key f1 pushed gpio_interrupt_handler(); // check if a new key has been pushed (sub mode - function to be programmed) if (buffer3[0] == 0xfe | buffer3[0] == 0xfd | buffer3[0] == 0xfb)
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 22 of 45 philips semiconductors an10315 led dimmer demoboard // key pushed = 1, 2, or 3 --> fun pattern programming { fun_pattern_programming(); } if (buffer3[0] == 0xf7) // key pushed = 4 --> backlight programming { backlight_programming(); } } buffer3[1] = 0xff; // clear key end pushed - leave programming mode message1.address = pca9531_m_wr; // pca9531 misc message1.nrbytes = 2; buffer1[0] = 0x16; // subaddress = 0x16 buffer1[1] = 0x00; // misc green led = off --> indicate led programming mode left i2c_write(&message1); // program pca9531 (2 bytes) } if (buffer3[1] == 0x7f) // push on f2 detected - enter simulation mode { message1.address = pca9531_m_wr; // pca9531 misc to indicate simulation mode message1.nrbytes = 2; buffer1[0] = 0x16; // subaddress = 0x06 buffer1[1] = 0x30; // ld11 blinking at br1 --> indicate simulation mode active i2c_write(&message1); // program pca9531 (2 bytes) while (buffer3[1] != 0xdf) // loop as long as end button not pushed (programming mode active) { buffer3[1] = 0xff; // clear key f2 pushed gpio_interrupt_handler(); // check if a new key has been pushed (sub mode - function to be programmed) if (buffer3[0] == 0xfe) // key pushed = 1 --> battery discharge emulation { battery_status(); } if (buffer3[0] == 0xf7) // key 4 pushed { auto_demo(); } } buffer3[1] = 0xff; // clear key end pushed - leave simulation mode message1.address = pca9531_m_wr; // pca9531 misc to indicate led programming mode message1.nrbytes = 2; buffer1[0] = 0x16; // subaddress = 0x06 buffer1[1] = 0x00; // ld11 blinking at br1 --> indicate led programming mode active i2c_write(&message1); // program pca9531 (2 bytes) } if (buffer3[0] != 0xff | buffer3[1] == 0xfe | buffer3[1] == 0xfd | buffer3[1] == 0xfb | buffer3[1] == 0xf7) { dial_number(); buffer3[1] = 0xff; // clear key end pushed } buffer3[1] = 0xff; // clear key end pushed }
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 23 of 45 philips semiconductors an10315 led dimmer demoboard //**************************************************************************** // main program //**************************************************************************** void main(void) { init_pca9564(); // initialization pca9564 init_white(); // initialization white led's init_rgb(); // initialization rgb led's init_misc(); // initialization misc led's init_gpio(); // initialization gpio intro_patterns(); // patterns displayed at power up while (1) { gpio_interrupt_handler(); function_select(); // enter a specific mode (programming, dial a number ...) } } 5.3 i2c_routines.c //************************************************************************* // p h i l i p s p r o p r i e t a r y // // copyright (c) 2003 by philips semiconductors // -- all rights reserved -- // // file name: i2c_routines.c // created: june 2, 2003 // modified: november 07, 2003 // revision: 1.00 //************************************************************************* #include #include "i2cexprt.h" #include "pca9564sys.h" unsigned char data_received; extern unsigned char crx; extern idata byte buffer1[32]; extern idata byte buffer2[32]; extern idata byte buffer3[16]; extern idata byte buffer4[16]; extern idata i2c_message message1; extern idata i2c_message message2; extern idata i2c_message message3; extern idata i2c_message message4; idata byte snapshot_1_1st_byte = 0x0f; idata byte snapshot_1_2nd_byte = 0x0f; idata byte snapshot_2_1st_byte = 0x00; idata byte snapshot_2_2nd_byte = 0x00; int trigger_gpio_polling; int gpio_polling_on = 0; // enable (1) or disable (0) the pca9555 polling option - default = off
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 24 of 45 philips semiconductors an10315 led dimmer demoboard void insertbigdelay(void) { insertdelay(255); insertdelay(255); insertdelay(255); insertdelay(255); insertdelay(255); } //**************************************************************************** // program the 3 pca9531 (r/g/b) with the same parameter(s) //**************************************************************************** void write_rgb_controller(void) { message1.address = pca9531_r_wr; i2c_write(&message1); message1.address = pca9531_g_wr; i2c_write(&message1); message1.address = pca9531_b_wr; i2c_write(&message1); } //**************************************************************************** // gpio interrupt handling function // one shot mode (through /int) or // permanent action detection (then input pca9554 reg# polling) //**************************************************************************** void gpio_interrupt_handler(void) { message2.address = pca9555_wr; message2.buf = buffer2; message2.nrbytes = 1; buffer2[0] = 0; //subaddress = 0 message3.address = pca9555_rd; message3.buf = buffer3; message3.nrbytes = 2; // read 2 bytes if (pca9555_int==0) // action on pushbutton detected { i2c_writerepread(&message2,&message3); // 1st read the pca9555 if (buffer3[0] ==0xff & buffer3[1] ==0xff); else { snapshot_1_1st_byte = buffer3[0]; // load the 1st read data (byte 1) in a temp memory snapshot_1_2nd_byte = buffer3[1]; // load the 1st read data (byte 2) in a temp memory } insertdelay(255); insertdelay(255); insertdelay(255); i2c_writerepread(&message2,&message3); // 2nd read the pca9555 snapshot_2_1st_byte = buffer3[0]; // load the 2nd read data (byte 1) in a temp memory snapshot_2_2nd_byte = buffer3[1]; // load the 2nd read data (byte 2) in a temp memory // compare the 2 read data in the temp memories if (snapshot_1_1st_byte == snapshot_2_1st_byte & snapshot_1_2nd_byte == snapshot_2_2nd_byte & gpio_polling_on == 1)
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 25 of 45 philips semiconductors an10315 led dimmer demoboard { trigger_gpio_polling = 1; // permanent push detected when 1st and 2nd readings equal } else { trigger_gpio_polling = 0; // single shot action when 1st and 2nd readings different buffer3[0] = snapshot_1_1st_byte; // buffer loaded again with the initial push value buffer3[1] = snapshot_1_2nd_byte; // buffer loaded again with the initial push value } } if (trigger_gpio_polling == 1) // start polling pca9554 when permanent push detected { i2c_writerepread(&message2,&message3); } } //**************************************************************************** // pattern displayed at power up or after a reset //**************************************************************************** void intro_patterns(void) { message1.nrbytes = 7; buffer1[0] = 0x11; // autoincrement + register 1 buffer1[1] = 0x00; // default prescaler pwm0 buffer1[2] = 0x3b; // default duty cycle for pwm0 buffer1[3] = 0x00; // default prescaler pwm1 buffer1[4] = 0x01; // default duty cycle for pwm1 buffer1[5] = 0x00; // green rgb led's = off buffer1[6] = 0x00; // green rgb led's = off message1.address = pca9531_r_wr; i2c_write(&message1); message1.address = pca9531_g_wr; i2c_write(&message1); message1.address = pca9531_b_wr; i2c_write(&message1); message1.nrbytes = 3; buffer1[0] = 0x15; buffer1[1] = 0x02; // ld13 @ br0 buffer1[2] = 0x00; write_rgb_controller(); insertdelay(250); buffer1[1] = 0x0a; // ld14 @ br0 buffer1[2] = 0x00; write_rgb_controller(); insertdelay(250); buffer1[1] = 0x20; // ld15 @ br0 buffer1[2] = 0x00; write_rgb_controller(); insertdelay(250); buffer1[1] = 0xa0; // ld16 @ br0 buffer1[2] = 0x00; write_rgb_controller(); insertdelay(250); buffer1[1] = 0x00; buffer1[2] = 0x02; // ld17 @ br0 write_rgb_controller(); insertdelay(250);
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 26 of 45 philips semiconductors an10315 led dimmer demoboard buffer1[1] = 0x00; buffer1[2] = 0x0a; // ld18 @ br0 write_rgb_controller(); insertdelay(250); buffer1[1] = 0x00; buffer1[2] = 0x20; // ld19 @ br0 write_rgb_controller(); insertdelay(250); buffer1[1] = 0x00; buffer1[2] = 0xa0; // ld20 @ br0 write_rgb_controller(); insertdelay(250); buffer1[1] = 0x02; // ld13 @ br0 buffer1[2] = 0x00; write_rgb_controller(); insertdelay(250); buffer1[1] = 0x00; // off buffer1[2] = 0x00; // off write_rgb_controller(); } //**************************************************************************** // function controlling number dial // number = 10 digits : xxx-xxx-xxxx // once dialed, snd button is pushed //**************************************************************************** idata byte key_pushed; short int call = 0; void dial_number(void) { int nb_key_pressed = 0; int one_to_eight = 0; int nine_zero = 0; call++; // when call = even number, line is busy - when call = odd number, line is not busy message1.address = pca9531_m_wr; // pca9531 misc message1.nrbytes = 6; // reset the pca9531 to its default programmed values message1.buf = buffer1; buffer1[0] = 0x11; // subaddress = 0x01 buffer1[1] = 0x97; // br0 = 1 hz buffer1[2] = 0x80; // br0 duty cycle = 50% buffer1[3] = 0x97; // br1 = 1 hz buffer1[4] = 0x08; // duty cycle br1 = 50% buffer1[5] = 0x00; // all 4 leds off i2c_write(&message1); // program pca9531 (6 bytes) message1.nrbytes = 2; while (buffer3[1] != 0xdf) // loop as long as end button not pushed (call not ended) { if (buffer3[0] != 0xff & nb_key_pressed < 11 & buffer3[1] != 0xef) // key pushed = 1, 2, 3, 4, 5, 6, 7, 8 and != snd { key_pushed = buffer3[0]; nb_key_pressed++; one_to_eight = 1; nine_zero = 0; }
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 27 of 45 philips semiconductors an10315 led dimmer demoboard if (buffer3[1] != 0xff & nb_key_pressed < 11 & buffer3[1] != 0xef) // key pushed = 9, 0 and != snd { key_pushed = buffer3[1]; nb_key_pressed++; one_to_eight = 0; nine_zero = 1; } if (nb_key_pressed < 11 & buffer3[1] != 0xef & (buffer3[0] != 0xff | buffer3[1] != 0xff)) { buffer3[0] = 0xff; // clear key pushed buffer3[1] = 0xff; // clear key pushed buffer1[0]= 0x15; // subaddress pca9531_m= 0x05 switch (key_pushed) { case 0xfe: if (one_to_eight == 1) // 1 pushed { buffer1[1] = 0x40; // ld8 = on i2c_write(&message1); // program pca9531 (2 bytes) } if (nine_zero == 1) // 9 pushed { buffer1[1] = 0x41; // ld5 and ld8 = on i2c_write(&message1); // program pca9531 (2 bytes) } break; case 0xfd: if (one_to_eight == 1) // 2 pushed { buffer1[1] = 0x10; // ld7 = on i2c_write(&message1); // program pca9531 (2 bytes) } if (nine_zero ==1) // 0 pushed { buffer1[1] = 0x00; // ld5 to ld8 = off i2c_write(&message1); // program pca9531 (2 bytes) } break; case 0xfb: // 3 pushed buffer1[1] = 0x50; // ld7 and ld8 = on i2c_write(&message1); // program pca9531 (2 bytes) break; case 0xf7: // 4 pushed buffer1[1] = 0x04; // ld6 = on i2c_write(&message1); // program pca9531 (2 bytes) break; case 0xef: // 5 pushed buffer1[1] = 0x44; // ld6 and ld8 = on i2c_write(&message1); // program pca9531 (2 bytes) break; case 0xdf: // 6 pushed buffer1[1] = 0x14; // ld6 and ld7 = on i2c_write(&message1); // program pca9531 (2 bytes) break; case 0xbf: // 7 pushed buffer1[1] = 0x54; // ld6, ld7 and ld8 = on i2c_write(&message1); // program pca9531 (2 bytes) break; case 0x7f: // 8 pushed buffer1[1] = 0x01; // ld5 = on
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 28 of 45 philips semiconductors an10315 led dimmer demoboard i2c_write(&message1); // program pca9531 (2 bytes) break; } } if (nb_key_pressed == 11 & buffer3[1] != 0xef) // more than 10 keys pushed and snd not pushed yet { buffer3[0] = 0xff; // clear key pushed buffer3[1] = 0xff; // clear key pushed buffer1[1] = 0xaa; // ld5 to ld8 = br0 to indicate that the 10 numbers have been dialed i2c_write(&message1); // program pca9531 (2 bytes) nb_key_pressed++; } if (buffer3[1] == 0xef) // snd pushed: send a call { buffer1[1] = 0x00; // ld5 to ld8 = off (dial number = done) i2c_write(&message1); // program pca9531 (2 bytes) message1.nrbytes = 7; buffer1[0] = 0x11; // subaddress = 0x01 buffer1[1] = 0x97; // br0 = 1 hz buffer1[2] = 0x80; // duty cycle br0 = 50% buffer1[3] = 0x00; // max freq br1 buffer1[4] = 0xff; // max duty cycle br1 buffer1[5] = 0xaa; // all 4 rgb leds blinking red buffer1[6] = 0xaa; // all 4 rgb leds blinking red if (call & 0x01) // busy signal { message1.address = pca9531_r_wr; // pca9531 red i2c_write(&message1); // program pca9531 (7 bytes) } else // non busy signal { message1.address = pca9531_g_wr; // pca9531 green i2c_write(&message1); // program pca9531 (7 bytes) } } buffer3[0] = 0xff; buffer3[1] = 0xff; gpio_interrupt_handler(); // check if a key has been pushed } message1.address = pca9531_m_wr; // pca9531 misc message1.nrbytes = 2; buffer1[1] = 0x00; // ld5 to ld8 = off (dial number = done) i2c_write(&message1); // program pca9531 (2 bytes) message1.nrbytes = 3; buffer1[2] = 0x00; // all rgb leds = off message1.address = pca9531_r_wr; // pca9531 red to switch off red leds i2c_write(&message1); // program pca9531 (3 bytes) message1.address = pca9531_g_wr; // pca9531 red to switch off green leds i2c_write(&message1); // program pca9531 (3 bytes) }
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 29 of 45 philips semiconductors an10315 led dimmer demoboard //**************************************************************************** // function controlling the duty cycle for a specific device // inputs = key "-", key "+", i2c address // output = new duty cycle value //**************************************************************************** short int duty_cycle_control(short int operation, short int i2c_address, short int duty_cycle_value) { message1.address = i2c_address; message1.nrbytes = 2; if (operation == decrement & duty_cycle_value > 0x00) // key pushed = 2 - decrease brightness { buffer1[0] = 0x02; // subaddress = 0x02 duty_cycle_value--; // decrement pwm 0 buffer1[1] = duty_cycle_value; i2c_write(&message1); // send new data to pca9531 (2 bytes) } if (operation == increment & duty_cycle_value < 0xff) // key pushed = 3 pushed - increase brightness { buffer1[0] = 0x02; // subaddress = 0x02 duty_cycle_value++; // increment pwm 0 buffer1[1] = duty_cycle_value; i2c_write(&message1); // send new data to pca9531 (2 bytes) } buffer3[0] = 0xff; // clear key plus pushed buffer3[1] = 0xff; // clear key plus pushed (key 9 only) return duty_cycle_value; } //**************************************************************************** // function controlling the backlight programming // entered by pushing 1 // key 2 = decrease brightness // key 3 = increase brightness // leave the mode by pushing end //**************************************************************************** idata byte duty_cycle_white; void backlight_programming (void) { buffer3[0] = 0xff; // clear key 1 pushed message1.address = pca9531_m_wr; // pca9531 misc to indicate backlight programming mode message1.nrbytes = 2; buffer1[0] = 0x15; // subaddress = 0x15 buffer1[1] = 0x40; // ld8 on --> backlight programming mode active i2c_write(&message1); gpio_polling_on = 1; // enable pca9555 polling option (see gpio_interrupt_handler function) message2.address = pca9533_w_wr; // read the current brightness value from the pca9533 message2.buf = buffer2; message2.nrbytes = 1; buffer2[0] = 0x02; // subaddress = 12 message3.address = pca9533_w_rd; message3.buf = buffer3; message3.nrbytes = 1; // read 1 byte i2c_writerepread(&message2,&message3); // read pwm0 of the pca9531 duty_cycle_white = buffer3[0]; while (buffer3[1] != 0xdf)
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 30 of 45 philips semiconductors an10315 led dimmer demoboard { gpio_interrupt_handler(); insertdelay(100); if (buffer3[0] == 0xfd) duty_cycle_white = duty_cycle_control(decrement, pca9533_w_wr, duty_cycle_white); // "-" red (key 2) if (buffer3[0] == 0xfb) duty_cycle_white = duty_cycle_control(increment, pca9533_w_wr, duty_cycle_white); // "+" red (key 3) } buffer3[1] = 0xff; // clear key end pushed gpio_polling_on = 0; // disable pca9555 gpio option message1.address = pca9531_m_wr; // pca9531 misc to indicate led programming mode message1.nrbytes = 2; buffer1[0] = 0x15; // subaddress = 0x15 buffer1[1] = 0x00; // ld8 off --> backlight programming mode left i2c_write(&message1); } //**************************************************************************** // function displaying a selected fun pattern // inputs = amount of red, green and blue, rotating speed //**************************************************************************** int fun_loop_counter = 1; int speed_prog_on = 0; void fun_pattern_display( short int red_value, short int green_value, short int blue_value, short int speed_value) { message1.buf = buffer1; message1.nrbytes = 2; buffer1[0] = 0x12; // subaddress = 12 message1.address = pca9531_r_wr; // pca9531 red buffer1[1] = red_value; // programming red i2c_write(&message1); // program pca9531 red (2 bytes) message1.address = pca9531_g_wr; // pca9531 green buffer1[1] = green_value; // programming green i2c_write(&message1); // program pca9531 green (2 bytes) message1.address = pca9531_b_wr; // pca9531 blue buffer1[1] = blue_value; // programming blue i2c_write(&message1); // program pca9531 blue (2 bytes) message1.nrbytes = 3; buffer1[0] = 0x15; // subaddress = 15 // loop as long as a pushbutton not pressed while (((buffer3[0]==0xff & buffer3[1]==0xff) | buffer3[1] == 0xfd | buffer3[1] == 0xf7) & speed_prog_on ==0) { if (fun_loop_counter < 8) { fun_loop_counter++; } else { fun_loop_counter = 1; } switch (fun_loop_counter) { case 1: buffer1[1] = 0x02; // programming ld13 blinking at br0 buffer1[2] = 0x00; // led's off break;
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 31 of 45 philips semiconductors an10315 led dimmer demoboard case 2: buffer1[1] = 0x08; // programming ld14 blinking at br0 buffer1[2] = 0x00; // led's off break; case 3: buffer1[1] = 0x20; // programming ld15 blinking at br0 buffer1[2] = 0x00; // led's off break; case 4: buffer1[1] = 0x80; // programming ld16 blinking at br0 buffer1[2] = 0x00; // led's off break; case 5: buffer1[1] = 0x00; // led's off buffer1[2] = 0x02; // programming ld17 blinking at br0 break; case 6: buffer1[1] = 0x00; // programming ld18 blinking at br0 buffer1[2] = 0x08; // led's off break; case 7: buffer1[1] = 0x00; // led's off buffer1[2] = 0x20; // programming ld19 blinking at br0 break; case 8: buffer1[1] = 0x00; // led's off buffer1[2] = 0x80; // programming ld20 blinking at br0 break; } message1.address = pca9531_r_wr; // pca9531 green i2c_write(&message1); // program pca9531 red (3 bytes) message1.address = pca9531_g_wr; // pca9531 green i2c_write(&message1); // program pca9531 green (3 bytes) message1.address = pca9531_b_wr; // pca9531 blue i2c_write(&message1); // program pca9531 blue (3 bytes) insertdelay(speed_value); // programmable delay insertdelay(speed_value); insertdelay(speed_value); gpio_interrupt_handler(); if (buffer3[1] == 0xfd | buffer3[1] == 0xf7) speed_prog_on = 1; } if ((buffer3[0]!=0xff | buffer3[1]!=0xff) & buffer3[1] != 0xfd & buffer3[1] != 0xf7) // all the leds blinking at br0 { message1.nrbytes = 3; buffer1[0] = 0x15; // subaddress = 15 buffer1[1] = 0xaa; // programming all led's blinking at br0 buffer1[2] = 0xaa; // programming all led's blinking at br0 message1.address = pca9531_r_wr; // pca9531 green i2c_write(&message1); // program pca9531 red (3 bytes) message1.address = pca9531_g_wr; // pca9531 green i2c_write(&message1); // program pca9531 green (3 bytes) message1.address = pca9531_b_wr; // pca9531 blue i2c_write(&message1); // program pca9531 blue (3 bytes) } }
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 32 of 45 philips semiconductors an10315 led dimmer demoboard //**************************************************************************** // function controlling the fun pattern programming // 3 programmable patterns: color and speed // entered by pushing 4 // key 1 = select pattern 1 // key 4 = select pattern 2 // key 7 = select pattern 3 // key 2 = decrease red of selected pattern // key 3 = increase red of selected pattern // key 5 = decrease green of selected pattern // key 6 = increase green of selected pattern // key 8 = decrease blue of selected pattern // key 9 = increase blue of selected pattern // key 0 = decrease speed of selected pattern // key # = increase speed of selected pattern //**************************************************************************** idata byte duty_cycle_r_one = 0x6b; idata byte duty_cycle_g_one = 0x01; idata byte duty_cycle_b_one = 0x25; idata byte duty_cycle_r_two = 0x01; idata byte duty_cycle_g_two = 0x6b; idata byte duty_cycle_b_two = 0x25; idata byte duty_cycle_r_three = 0x26; idata byte duty_cycle_g_three = 0x6b; idata byte duty_cycle_b_three = 0x01; int speed_one = 255; int speed_two = 25; int speed_three = 100; void fun_pattern_programming (void) { init_rgb(); gpio_interrupt_handler(); // check if an action on pushbutton happened if (buffer3[0] == 0xfe) // pattern 1 selected - key 1 pushed { buffer3[0] = 0xff; // clear key 1 pushed message1.address = pca9531_m_wr; // pca9531 misc to indicate backlight programming mode message1.nrbytes = 2; buffer1[0] = 0x15; // subaddress = 0x15 buffer1[1] = 0x01; // ld5 on --> pattern 1 programming active i2c_write(&message1); while (buffer3[1]!=0xdf) // loop as long as end button not pushed (fun pattern 1 programming active) { buffer3[1] = 0xff; gpio_interrupt_handler(); // check if an action on pushbutton happened gpio_polling_on = 1; // enable pca9555 polling option (see gpio_interrupt_handler function) fun_pattern_display(duty_cycle_r_one, duty_cycle_g_one, duty_cycle_b_one, speed_one); if (buffer3[0] == 0xfd) duty_cycle_r_one = duty_cycle_control(decrement, pca9531_r_wr, duty_cycle_r_one); // "-" red (key 2) if (buffer3[0] == 0xfb) duty_cycle_r_one = duty_cycle_control(increment, pca9531_r_wr, duty_cycle_r_one); // "+" red (key 3) if (buffer3[0] == 0xef) duty_cycle_g_one = duty_cycle_control(decrement, pca9531_g_wr, duty_cycle_g_one); // "-" green (key 5)
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 33 of 45 philips semiconductors an10315 led dimmer demoboard if (buffer3[0] == 0xdf) duty_cycle_g_one = duty_cycle_control(increment, pca9531_g_wr, duty_cycle_g_one); // "+" green (key 6) if (buffer3[0] == 0x7f) duty_cycle_b_one = duty_cycle_control(decrement, pca9531_b_wr, duty_cycle_b_one); // "-" blue (key 8) if (buffer3[1] == 0xfe) duty_cycle_b_one = duty_cycle_control(increment, pca9531_b_wr, duty_cycle_b_one); // "+" blue (key 9) if (buffer3[1] == 0xfd & speed_one > 0) { speed_one--; } if (buffer3[1] == 0xf7 & speed_one < 255) { speed_one++; } speed_prog_on = 0; gpio_polling_on = 0; // disable pca9555 gpio polling option } buffer3[0] = 0xff; buffer3[1] = 0xff; message1.address = pca9531_m_wr; // pca9531 misc to indicate backlight programming mode message1.nrbytes = 2; buffer1[0] = 0x15; // subaddress = 0x15 buffer1[1] = 0x00; // ld5 off --> pattern 1 programming left i2c_write(&message1); } if (buffer3[0] == 0xfd) // pattern 2 selected - key 2 pushed { buffer3[0] = 0xff; // clear key 2 pushed message1.address = pca9531_m_wr; // pca9531 misc to indicate backlight programming mode message1.nrbytes = 2; buffer1[0] = 0x15; // subaddress = 0x15 buffer1[1] = 0x04; // ld6 on --> pattern 2 programming active i2c_write(&message1); while (buffer3[1]!=0xdf) // loop as long as end button not pushed (fun pattern 2 programming active) { buffer3[1] = 0xff; gpio_interrupt_handler(); // check if an action on pushbutton happened gpio_polling_on = 1; // enable pca9555 polling option (see gpio_interrupt_handler function) fun_pattern_display(duty_cycle_r_two, duty_cycle_g_two, duty_cycle_b_two, speed_two); if (buffer3[0] == 0xfd) duty_cycle_r_two = duty_cycle_control(decrement, pca9531_r_wr, duty_cycle_r_two); // "-" red (key 2) if (buffer3[0] == 0xfb) duty_cycle_r_two = duty_cycle_control(increment, pca9531_r_wr, duty_cycle_r_two); // "+" red (key 3) if (buffer3[0] == 0xef) duty_cycle_g_two = duty_cycle_control(decrement, pca9531_g_wr, duty_cycle_g_two); // "-" green (key 5) if (buffer3[0] == 0xdf) duty_cycle_g_two = duty_cycle_control(increment, pca9531_g_wr, duty_cycle_g_two); // "+" green (key 6) if (buffer3[0] == 0x7f) duty_cycle_b_two = duty_cycle_control(decrement, pca9531_b_wr, duty_cycle_b_two); // "-" blue (key 8) if (buffer3[1] == 0xfe) duty_cycle_b_two = duty_cycle_control(increment, pca9531_b_wr, duty_cycle_b_two); // "+" blue (key 9) if (buffer3[1] == 0xfd & speed_two > 0) { speed_two--; }
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 34 of 45 philips semiconductors an10315 led dimmer demoboard if (buffer3[1] == 0xf7 & speed_two < 255) { speed_two++; } speed_prog_on = 0; gpio_polling_on = 0; // disable pca9555 gpio polling option } buffer3[1] = 0xff; message1.address = pca9531_m_wr; // pca9531 misc to indicate backlight programming mode message1.nrbytes = 2; buffer1[0] = 0x15; // subaddress = 0x15 buffer1[1] = 0x00; // ld6 off --> pattern 2 programming left i2c_write(&message1); } if (buffer3[0] == 0xfb) // pattern 3 selected - key 3 pushed { buffer3[0] = 0xff; // clear key 3 pushed message1.address = pca9531_m_wr; // pca9531 misc to indicate backlight programming mode message1.nrbytes = 2; buffer1[0] = 0x15; // subaddress = 0x15 buffer1[1] = 0x10; // ld7 on --> pattern 3 programming active i2c_write(&message1); while (buffer3[1]!=0xdf) // loop as long as end button not pushed (fun pattern 1 programming active) { buffer3[1] = 0xff; gpio_interrupt_handler(); // check if an action on pushbutton happened gpio_polling_on = 1; // enable pca9555 polling option (see gpio_interrupt_handler function) fun_pattern_display(duty_cycle_r_three, duty_cycle_g_three, duty_cycle_b_three, speed_three); if (buffer3[0] == 0xfd) duty_cycle_r_three = duty_cycle_control(decrement, pca9531_r_wr, duty_cycle_r_three); // "-" red (key 2) if (buffer3[0] == 0xfb) duty_cycle_r_three = duty_cycle_control(increment, pca9531_r_wr, duty_cycle_r_three); // "+" red (key 3) if (buffer3[0] == 0xef) duty_cycle_g_three = duty_cycle_control(decrement, pca9531_g_wr, duty_cycle_g_three); // "-" green (key 5) if (buffer3[0] == 0xdf) duty_cycle_g_three = duty_cycle_control(increment, pca9531_g_wr, duty_cycle_g_three); // "+" green (key 6) if (buffer3[0] == 0x7f) duty_cycle_b_three = duty_cycle_control(decrement, pca9531_b_wr, duty_cycle_b_three); // "-" blue (key 8) if (buffer3[1] == 0xfe) duty_cycle_b_three = duty_cycle_control(increment, pca9531_b_wr, duty_cycle_b_three); // "+" blue (key 9) if (buffer3[1] == 0xfd & speed_three > 0) { speed_three--; } if (buffer3[1] == 0xf7 & speed_three < 255) { speed_three++; } speed_prog_on = 0; gpio_polling_on = 0; // disable pca9555 gpio polling option } // end programming pattern 3 (end pushed and detected) buffer3[1] = 0xff; message1.address = pca9531_m_wr; // pca9531 misc to indicate backlight programming mode message1.nrbytes = 2; buffer1[0] = 0x15; // subaddress = 0x15 buffer1[1] = 0x00; // ld7 off --> pattern 1 programming left
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 35 of 45 philips semiconductors an10315 led dimmer demoboard i2c_write(&message1); } // end if message1.address = pca9531_r_wr; // pca9531 red message1.nrbytes = 3; buffer1[0] = 0x15; // subaddress = 15 buffer1[1] = 0x00; // all red led's off buffer1[2] = 0x00; // all red led's off i2c_write(&message1); message1.address = pca9531_g_wr; // pca9531 all green led's off i2c_write(&message1); message1.address = pca9531_b_wr; // pca9531 all blue led's off i2c_write(&message1); buffer3[1] = 0xff; // clear key end pushed } //**************************************************************************** // function emulating a battery discharge // pushing key 3 discharges the battery (level can be seen with ld5 to ld8 // pushing 6 resets the emulation (battery fully charged again //**************************************************************************** void battery_status (void) { int battery_level = 0xff; buffer3[0] = 0xff; // clear key 1 pushed message1.address = pca9531_m_wr; // pca9531 misc message1.nrbytes = 7; buffer1[0] = 0x11; // subaddress = 0x01 buffer1[1] = 0x97; // blinking rate buffer1[2] = 0xf0; // high duty cycle when battery charge > 50% buffer1[3] = 0x97; // default prescaler pwm1 = 1 hz buffer1[4] = 0x08; // default duty cycle for pwm1 = 50% buffer1[5] = 0x55; // ld5 to ld8 on --> indicate battery fully charged buffer1[6] = 0x32; // rg led green blinking at br0 i2c_write(&message1); while (buffer3[1]!=0xdf) // loop as long as end button not pushed (fun pattern 2 programming active) { insertdelay(150); buffer3[1] = 0xff; gpio_interrupt_handler(); // check if an action on pushbutton happened gpio_polling_on = 1; // enable pca9555 polling option (see gpio_interrupt_handler function) if (buffer3[0] == 0xfb) // key 3 pushed - battery is discharging when key 3 pushed (continuous) { if (battery_level != 0x00) battery_level--; if (battery_level == 0xc0) { message1.address = pca9531_m_wr; // pca9531 misc message1.nrbytes = 2; buffer1[0] = 0x15; // subaddress = 0x05 buffer1[1] = 0x54; // ld5 now off i2c_write(&message1); } if (battery_level == 0x80) { message1.address = pca9531_m_wr; // pca9531 misc message1.nrbytes = 6;
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 36 of 45 philips semiconductors an10315 led dimmer demoboard buffer1[0] = 0x12; // subaddress = 0x02 buffer1[1] = 0x80; // rg (orange) led shorter duty cycle buffer1[2] = 0x97; // default prescaler pwm1 = 1 hz buffer1[3] = 0x08; // default duty cycle for pwm1 = 50% buffer1[4] = 0x50; // ld5 and ld6 now off buffer1[5] = 0x3a; // rg led green and red blinking at br0 (orange) i2c_write(&message1); } if (battery_level == 0x40) { message1.address = pca9531_m_wr; // pca9531 misc message1.nrbytes = 6; buffer1[0] = 0x12; // subaddress = 0x02 buffer1[1] = 0x10; // rg (red only) led even shorter duty cycle buffer1[2] = 0x97; // default prescaler pwm1 = 1 hz buffer1[3] = 0x08; // default duty cycle for pwm1 = 50% buffer1[4] = 0x40; // ld5, ld6 and ld7 now off buffer1[5] = 0x38; // rg led green and red blinking at br0 i2c_write(&message1); } if (battery_level == 0x00) { message1.address = pca9531_m_wr; // pca9531 misc message1.nrbytes = 6; buffer1[0] = 0x12; // subaddress = 0x02 buffer1[1] = 0x01; // duty cycle = 0x01 --> red led actually almost off buffer1[2] = 0x97; // default prescaler pwm1 = 1 hz buffer1[3] = 0x08; // default duty cycle for pwm1 = 50% buffer1[4] = 0x00; // ld5, ld6, ld7 and ld8 now off buffer1[5] = 0x38; // rg led green and red blinking at br0 i2c_write(&message1); } } if (buffer3[0] == 0xdf) // reset the simulation and recharge completly the battery (key 6 pushed) { battery_level = 0xff; message1.address = pca9531_m_wr; // pca9531 misc message1.nrbytes = 6; buffer1[0] = 0x12; // subaddress = 0x02 buffer1[1] = battery_level - 0x10; // high duty cycle when battery charge > 50% buffer1[2] = 0x97; // default prescaler pwm1 = 1 hz buffer1[3] = 0x08; // default duty cycle for pwm1 = 50% buffer1[4] = 0x55; // ld5 to ld8 on --> indicate battery fully charged buffer1[5] = 0x32; // rg led green blinking at br0 i2c_write(&message1); } buffer3[0] = 0xff; // clear key 3 pushed } gpio_polling_on = 0; // disable pca9555 polling option (see gpio_interrupt_handler function) buffer3[1] = 0xff; message1.address = pca9531_m_wr; // pca9531 misc message1.nrbytes = 3; buffer1[0] = 0x15; buffer1[1] = 0x00; // ld5 to ld8 off buffer1[2] = 0x30; i2c_write(&message1); }
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 37 of 45 philips semiconductors an10315 led dimmer demoboard //**************************************************************************** // auto demo mode // reset only allows leaving this mode //**************************************************************************** void auto_demo(void) { int i; int j; int k; message1.buf = buffer1; message1.nrbytes = 7; message1.address = pca9531_r_wr; buffer1[0] = 0x11; // autoincrement + register 1 buffer1[1] = 0x00; // default prescaler pwm0 buffer1[2] = 0x6b; // default duty cycle for pwm0 buffer1[3] = 0x00; // default prescaler pwm1 buffer1[4] = 0x01; // default duty cycle for pwm1 buffer1[5] = 0x00; // green rgb led's = off buffer1[6] = 0x00; // green rgb led's = off i2c_write(&message1); message1.address = pca9531_g_wr; buffer1[0] = 0x11; // autoincrement + register 1 buffer1[1] = 0x00; // default prescaler pwm0 buffer1[2] = 0x01; // default duty cycle for pwm0 buffer1[3] = 0x00; // default prescaler pwm1 buffer1[4] = 0x6b; // default duty cycle for pwm1 buffer1[5] = 0x00; // green rgb led's = off buffer1[6] = 0x00; // green rgb led's = off i2c_write(&message1); message1.address = pca9531_b_wr; buffer1[0] = 0x11; // autoincrement + register 1 buffer1[1] = 0x00; // default prescaler pwm0 buffer1[2] = 0x25; // default duty cycle for pwm0 buffer1[3] = 0x00; // default prescaler pwm1 buffer1[4] = 0x25; // default duty cycle for pwm1 buffer1[5] = 0x00; // green rgb led's = off buffer1[6] = 0x00; // green rgb led's = off i2c_write(&message1); message1.nrbytes = 3; buffer1[0] = 0x15; // animation 1 for (i = 0; i < 3; i++) { buffer1[1] = 0xee; // ld13 and 15 @ br0 - ld14 and 16 @ br1 buffer1[2] = 0xee; // ld17 and 19 @ br0 - ld18 and 20 @ br1 write_rgb_controller(); insertbigdelay(); buffer1[1] = 0xbb; // ld13 and 15 @ br1 - ld14 and 16 @ br0 buffer1[2] = 0xbb; // ld17 and 19 @ br1 - ld18 and 20 @ br0 write_rgb_controller(); insertbigdelay(); }
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 38 of 45 philips semiconductors an10315 led dimmer demoboard // animation 2 buffer1[1] = 0xaa; // ld13-16 @ br0 buffer1[2] = 0xaa; // ld17-20 @ br0 write_rgb_controller(); insertbigdelay(); buffer1[1] = 0xab; // ld13 @ br1 - ld14-16 @ br0 buffer1[2] = 0xaa; // ld17-20 @ br0 write_rgb_controller(); insertbigdelay(); buffer1[1] = 0xae; // ld14 @ br1 - ld13,14,16 @ br0 buffer1[2] = 0xaa; // ld17-20 @ br0 write_rgb_controller(); insertbigdelay(); buffer1[1] = 0xba; // ld15 @ br1 - ld13,14,16 @ br0 buffer1[2] = 0xaa; // ld17-20 @ br0 write_rgb_controller(); insertbigdelay(); buffer1[1] = 0xea; // ld16 @ br1 - ld13-15 @ br0 buffer1[2] = 0xaa; // ld17-20 @ br0 write_rgb_controller(); insertbigdelay(); buffer1[1] = 0xaa; // ld13-16 @ br0 buffer1[2] = 0xab; // ld17 @ br1 - ld18-20 @ br0 write_rgb_controller(); insertbigdelay(); buffer1[1] = 0xaa; // ld13-16 @ br0 buffer1[2] = 0xae; // ld18 @ br1 - ld17,19,20 @ br0 write_rgb_controller(); insertbigdelay(); buffer1[1] = 0xaa; // ld13-16 @ br0 buffer1[2] = 0xba; // ld19 @ br1 - ld17,18,20 @ br0 write_rgb_controller(); insertbigdelay(); buffer1[1] = 0xaa; // ld13-16 @ br0 buffer1[2] = 0xea; // ld18 @ br1 - ld17,19,20 @ br0 write_rgb_controller(); insertbigdelay(); buffer1[1] = 0xaa; // ld13-16 @ br0 buffer1[2] = 0xaa; // ld17-20 @ br0 write_rgb_controller(); insertbigdelay(); // animation 3 for (i = 0; i < 3; i++) { buffer1[1] = 0xab; // ld13@br1, ld14-15-16@br0 buffer1[2] = 0xab; // ld17@br1, ld18-19-20@br0 write_rgb_controller(); insertbigdelay(); buffer1[1] = 0xae; // ld14@br1, ld13-15-16@br0 buffer1[2] = 0xae; // ld18@br1, ld17-19-20@br0 write_rgb_controller(); insertbigdelay(); buffer1[1] = 0xba; // ld15@br1, ld13-14-16@br0 buffer1[2] = 0xba; // ld19@br1, ld17-18-20@br0 write_rgb_controller(); insertbigdelay();
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 39 of 45 philips semiconductors an10315 led dimmer demoboard buffer1[1] = 0xea; // ld16@br1, ld13-14-15@br0 buffer1[2] = 0xea; // ld20@br1, ld17-18-19@br0 write_rgb_controller(); insertbigdelay(); } // animation 4 buffer1[1] = 0x00; // ld13-16 = off buffer1[2] = 0x00; // ld17-20 = off write_rgb_controller(); for (i = 0; i < 3; i++) { message1.address = pca9531_r_wr; buffer1[1] = 0x41; // ld13,ld16 = red buffer1[2] = 0x10; // ld19 = red i2c_write(&message1); message1.address = pca9531_g_wr; buffer1[1] = 0x04; // ld14 = green buffer1[2] = 0x41; // ld17,20 = green i2c_write(&message1); message1.address = pca9531_b_wr; buffer1[1] = 0x10; // ld15 = blue buffer1[2] = 0x04; // ld18 = blue i2c_write(&message1); insertbigdelay(); message1.address = pca9531_g_wr; buffer1[1] = 0x41; // ld13,ld16 = green buffer1[2] = 0x10; // ld19 = green i2c_write(&message1); message1.address = pca9531_b_wr; buffer1[1] = 0x04; // ld14 = blue buffer1[2] = 0x41; // ld17,20 = blue i2c_write(&message1); message1.address = pca9531_r_wr; buffer1[1] = 0x10; // ld15 = red buffer1[2] = 0x04; // ld18 = red i2c_write(&message1); insertbigdelay(); message1.address = pca9531_b_wr; buffer1[1] = 0x41; // ld13,ld16 = blue buffer1[2] = 0x10; // ld19 = blue i2c_write(&message1); message1.address = pca9531_r_wr; buffer1[1] = 0x04; // ld14 = red buffer1[2] = 0x41; // ld17,20 = red i2c_write(&message1); message1.address = pca9531_g_wr; buffer1[1] = 0x10; // ld15 = green buffer1[2] = 0x04; // ld18 = green i2c_write(&message1); insertbigdelay(); } message1.nrbytes = 7; message1.address = pca9531_r_wr; buffer1[0] = 0x11; // autoincrement + register 1 buffer1[1] = 0x00; // default prescaler pwm0
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 40 of 45 philips semiconductors an10315 led dimmer demoboard buffer1[2] = 0x00; // default duty cycle for pwm0 buffer1[3] = 0x00; // default prescaler pwm1 buffer1[4] = 0x00; // default duty cycle for pwm1 buffer1[5] = 0xaa; // green rgb led's = br0 buffer1[6] = 0xaa; // green rgb led's = br0 i2c_write(&message1); message1.address = pca9531_g_wr; buffer1[0] = 0x11; // autoincrement + register 1 buffer1[1] = 0x00; // default prescaler pwm0 buffer1[2] = 0x00; // default duty cycle for pwm0 buffer1[3] = 0x00; // default prescaler pwm1 buffer1[4] = 0x00; // default duty cycle for pwm1 buffer1[5] = 0xaa; // green rgb led's = br0 buffer1[6] = 0xaa; // green rgb led's = br0 i2c_write(&message1); message1.address = pca9531_b_wr; buffer1[0] = 0x11; // autoincrement + register 1 buffer1[1] = 0x00; // default prescaler pwm0 buffer1[2] = 0x00; // default duty cycle for pwm0 buffer1[3] = 0x00; // default prescaler pwm1 buffer1[4] = 0x00; // default duty cycle for pwm1 buffer1[5] = 0xaa; // green rgb led's = br0 buffer1[6] = 0xaa; // green rgb led's = br0 i2c_write(&message1); message1.nrbytes = 2; buffer1[0] = 0x12; // red only from min to max brightness message1.address = pca9531_r_wr; for (i = 0x00; i < 0xff; i++) { buffer1[1] = i; i2c_write(&message1); insertdelay(40); }; buffer1[1] = 0x00; // no red i2c_write(&message1); // green only from min to max brightness message1.address = pca9531_g_wr; for (j = 0x00; j < 0xff; j++) { buffer1[1] = j; i2c_write(&message1); insertdelay(40); }; buffer1[1] = 0x00; // no green i2c_write(&message1); // blue only from min to max brightness message1.address = pca9531_b_wr; for (k = 0x00; k < 0xff; k++) { buffer1[1] = k; i2c_write(&message1); insertdelay(40); };
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 41 of 45 philips semiconductors an10315 led dimmer demoboard buffer1[1] = 0x00; // no blue i2c_write(&message1); // some color mixing 1 message1.address = pca9531_r_wr; // program some red buffer1[1] = 0x36; i2c_write(&message1); message1.address = pca9531_g_wr; // program some green buffer1[1] = 0x2b; i2c_write(&message1); message1.address = pca9531_b_wr; for (k = 0x00; k < 0xff; k++) // increase amount of blue { buffer1[1] = k; insertdelay(40); i2c_write(&message1); }; // some color mixing 2 buffer1[1] = 0x0a; // program some blue i2c_write(&message1); message1.address = pca9531_g_wr; // program some green buffer1[1] = 0x0a; i2c_write(&message1); message1.address = pca9531_r_wr; for (i = 0x00; i <0xff; i++) // increase amount of red { buffer1[1] = i; i2c_write(&message1); insertdelay(40); }; // some color mixing 3 buffer1[1] = 0x10; // program some red i2c_write(&message1); message1.address = pca9531_b_wr; buffer1[1] = 0x0a; // program some blue i2c_write(&message1); message1.address = pca9531_g_wr; for (j = 0x00; j < 0xff; j++) // increase amount of green { buffer1[1] = j; i2c_write(&message1); insertdelay(40); }; // some color mixing 4 buffer1[1] = 0x00; // no color message1.address = pca9531_r_wr; i2c_write(&message1); message1.address = pca9531_g_wr; i2c_write(&message1); message1.address = pca9531_b_wr; i2c_write(&message1); message1.address = pca9531_r_wr; for (i = 0x00; i < 0xff; i++) // increase amount of red { buffer1[1] = i;
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 42 of 45 philips semiconductors an10315 led dimmer demoboard i2c_write(&message1); insertdelay(40); }; message1.address = pca9531_g_wr; for (j = 0x00; j < 0xff; j++) // increase amount of green { buffer1[1] = j; i2c_write(&message1); insertdelay(40); }; buffer1[1] = 0x00; // remove green i2c_write(&message1); message1.address = pca9531_b_wr; for (k = 0x00; k < 0xff; k++) // increase amount of blue { buffer1[1] = k; i2c_write(&message1); insertdelay(40); }; message1.address = pca9531_r_wr; buffer1[1] = 0x00; // remove red i2c_write(&message1); message1.address = pca9531_g_wr; for (j = 0x00; j < 0xff; j++) // increase amount of green { buffer1[1] = j; i2c_write(&message1); insertdelay(40); }; buffer1[1] = 0x00; // remove green i2c_write(&message1); message1.address = pca9531_r_wr; for (i = 0x00; i < 0xff; i++) // increase amount of red { buffer1[1] = i; i2c_write(&message1); insertdelay(40); }; buffer1[1] = 0x00; // remove red i2c_write(&message1); message1.address = pca9531_g_wr; buffer1[1] = 0xff; // max green i2c_write(&message1); message1.address = pca9531_b_wr; for (k = 0x00; k < 0xff; k++) // increase amount of blue { buffer1[1] = k; i2c_write(&message1); insertdelay(40); }; buffer1[1] = 0x00; // remove blue i2c_write(&message1); message1.address = pca9531_r_wr; for (i = 0x00; i < 0xff; i++) // increase amount of red { buffer1[1] = i; i2c_write(&message1); insertdelay(40);
9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 43 of 45 philips semiconductors an10315 led dimmer demoboard }; message1.address = pca9531_g_wr; for (j = 0x00; j < 0xff; j++) // increase amount of green { buffer1[1] = j; i2c_write(&message1); insertdelay(40); }; } // end of the i2c routines //
philips semiconductors an10315 led dimmer demoboard 9397 750 14062 ? koninklijke philips electronics n.v. 2005. all rights reserved. application note rev. 01 ? 7 january 2005 44 of 45 6. disclaimers life support ? these products are not designed for use in life support appliances, devices, or systems wher e malfunction of these products can reasonably be expected to result in personal injury. philips semiconductors customers using or selling these products for use in such applications do so at their own risk and agree to fully indemnify philips semiconductors for any damages resulting from such application. right to make changes ? philips semiconductors reserves the right to make changes in the products - including circuits, standard cells, and/or software - described or contained herein in order to improve design and/or performance. when the product is in fu ll production (status ?production?), relevant changes will be communicated via a customer product/process change notification (cpcn). philips semiconductors assumes no responsibility or liability for the use of any of these products, conveys no licence or title under any patent, copyright, or mask work right to these products, and makes no representations or warranties that these products are free from patent, copyright, or mask work right infringement, unless otherwise specified. application information ? applications that are described herein for any of these products are for illustrative purposes only. philips semiconductors make no representation or warranty that such applications will be suitable for the specified use without further testing or modification. 7. licenses purchase of philips i 2 c components purchase of philips i 2 c components conveys a license under the philips? i 2 c patent to use the components in the i 2 c system provided the system conforms to the i 2 c specification defined by philips. this specification can be ordered using the code 9398 393 40011.
? koninklijke philips electronics n.v. 2005 all rights are reserved. reproduction in whole or in part is prohibited without the prior written consent of the copyright owner. the information presented in this document does not form part of any quotation or contract, is believed to be accurate and reliable and may be changed without notice. no liability will be accepted by the publisher for any consequence of its use. publication thereof does not convey nor imply any license under patent- or other industrial or intellectual property rights. date of release: 7 january 2005 document number: 9397 750 14062 published in the netherlands philips semiconductors an10315 led dimmer demoboard 8. contents 1 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2 ordering information . . . . . . . . . . . . . . . . . . . . . 3 3 technical information?hardware . . . . . . . . . . 4 3.1 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . 4 3.2 i 2 c-bus device addresses. . . . . . . . . . . . . . . . . 4 3.3 schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 3.3.1 keypad control card . . . . . . . . . . . . . . . . . . . . . 5 3.3.2 led control card . . . . . . . . . . . . . . . . . . . . . . . . 6 3.4 demoboard (top view) . . . . . . . . . . . . . . . . . . . 7 3.5 rgb color mixing . . . . . . . . . . . . . . . . . . . . . . . 8 4 technical information?how to use the demobord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4.1 introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4.2 firmware routines. . . . . . . . . . . . . . . . . . . . . . 10 4.3 dialing routine. . . . . . . . . . . . . . . . . . . . . . . . . 11 4.3.1 how the keypad control works . . . . . . . . . . . . 11 4.3.2 keypad mapping with the pca9555 i/os . . . . 11 4.3.3 application: cell phone type keyboard? dialing routine. . . . . . . . . . . . . . . . . . . . . . . . . 12 4.4 programming mode . . . . . . . . . . . . . . . . . . . . 13 4.4.1 programming fun patterns routine? rgb color mixing . . . . . . . . . . . . . . . . . . . . . . 13 4.4.2 pca953x mapping with the leds . . . . . . . . . 14 4.4.3 white led control routine. . . . . . . . . . . . . . . . 14 4.5 emulation mode: battery discharge application 15 4.6 auto demo routine . . . . . . . . . . . . . . . . . . . . . 15 4.7 reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 4.8 how to code i 2 c commands using the p89lv51rd2/pca9564 . . . . . . . . . . . . . . . . . 16 5 source code . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 5.1 i2cexpert.h . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 5.2 mainloop.c . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 5.3 i2c_routines.c . . . . . . . . . . . . . . . . . . . . . . . . 23 6 disclaimers. . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 7 licenses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44


▲Up To Search▲   

 
Price & Availability of AN10315-15

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X